// PluginLoader.h

#ifndef __PLUGIN_LOADER_H
#define __PLUGIN_LOADER_H

#include "Common/System/DLL.h"
#include "../FileSystem/IFolder.h"

namespace Common
{
namespace Plugin
{

class CPluginLibrary: public Common::System::DLL::CLibrary
{
	typedef UINT32 (WINAPI* CreateObjectPointer)(const GUID* clsID, const GUID* interfaceID, void** outObject);
public:
	HRESULT CreateManager(REFGUID clsID, IFolderManager** manager)
	{
		CreateObjectPointer createObject = (CreateObjectPointer)GetProcAddress("CreateObject");
		if (createObject == NULL)
		{
			return GetLastError();
		}
		return createObject(&clsID, &__uuidof(IFolderManager), (void**)manager);
	}
	HRESULT LoadAndCreateManager(LPCWSTR filePath, REFGUID clsID, IFolderManager** manager)
	{
		if (!Load(filePath))
		{
			return GetLastError();
		}
		return CreateManager(clsID, manager);
	}
};

}
}

#endif
